<template>
    <div class="container">
        <el-tabs v-model="activeName">
            <el-tab-pane label="门店管理" name="1">
                <el-table v-loading="menLoading" :data="menDianList" class="el-mb-15" stripe>
                    <el-table-column prop="id" label="ID"/>
                    <el-table-column prop="zhicheng" label="名称"/>
                    <el-table-column label="冻结状态">
                        <template slot-scope="scope">
                            {{scope.row.dongjie==0 ?"冻结":"正常"}}
                             
                        </template>
                    </el-table-column>
                     <el-table-column label="审核状态">
                        <template>
                           
                          {{zhuangtai}}
                           
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作">
                        <template slot-scope="scope">
                            <el-button v-show="isow" @click.stop="dongjieClick(1,scope.row.id)" type="primary"
                                       v-if="scope.row.dongjie==0" plain size="small">解冻
                            </el-button>
                            <el-button v-show="isow"  @click.stop="dongjieClick(0,scope.row.id)" plain type="danger" size="small"
                                       v-else>冻结
                            </el-button>
                              <el-button @click.stop="shenghe(1,scope.row.id)" plain type="danger" size="small">审核</el-button>
                            
                            
                        </template>
                    </el-table-column>
                </el-table>
                <!-- <el-pagination
                     @size-change="eventUpdateRequestLimit" @current-change="onLoadMenDian"
                     :current-page="menQuery.page" :page-size="menQuery.list_rows" :total="menQuery.total"
                     :page-sizes="[10, 50, 100, 200, 300]"
                     layout="total, sizes, prev, pager, next, jumper"
                 ></el-pagination>-->

            </el-tab-pane>
            <el-tab-pane label="暂存点管理" name="2">
                <el-table v-loading="yewuLoading" :data="yewuList" class="el-mb-15" stripe>
                    <el-table-column prop="id" label="ID"/>
                    <el-table-column prop="zhicheng" label="名称"/>
                    <el-table-column label="状态">
                        <template slot-scope="scope">
                            {{scope.row.dongjie==0 ?"冻结":"正常"}}
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作">
                        <template slot-scope="scope">
                            <el-button @click.stop="dongjieClick(1,scope.row.id)" type="primary"
                                       v-if="scope.row.dongjie==0" plain size="small">解冻
                            </el-button>
                            <el-button @click.stop="dongjieClick(scope.row.id)" plain type="danger" size="small"
                                       v-else>冻结
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
              
            </el-tab-pane>
        </el-tabs>
         <van-dialog v-model="showAdd" title="是否通过审核?" show-cancel-button @confirm="shenhe()">
			
			
		</van-dialog>


    </div>
</template>

<script>

    import fly from "../../../src/libs/js/request.js"


    export default {

        components: {},
        data() {
            return {
                sz:"",
                isow: "",
                zhuangtai:"",
                uid:"",
                showAdd: false,
                activeName: "1",
                shen:"1",
                menDianList: [],
                menFinished: false,
                menLoading: false,
                menQuery: {
                    total: 0,
                    page: 0,
                    list_rows: 100,
                },
                yewuList: [/*{
                    "id": 73,
                    "name": "152336642801",
                    "pwd": "c4ca4238a0b923820dcc509a6f75849b",
                    "phone": 152336642801,
                    "status": 2,
                    "region": "130102",
                    "zregionnumber": "158",
                    "zregionweight": "0",
                    "upid": 71,
                    "ywyid": 0,
                    "groupid": 1,
                    "token": "0e4e3982a20dcabd3a843cc3d3904e98",
                    "del": 0,
                    "txprice": "0",
                    "saleid": 0,
                    "tempid": 0,
                    "price": "158",
                    "longitude": "38.085057",
                    "latitude": "114.548294",
                    "realname": "长安区门店",
                    "zhicheng": "长安区门店",
                    "pic": null,
                    "jifen": "148",
                    "address": "建华北大街与御城路交叉口东100米",
                    "openid": "shadow",
                    "province": 0,
                    "city": 0,
                    "county": 130102,
                    "reason": null,
                    "dprice": "-158",
                    "daili": 0,
                    "huan": 0,
                    "userinfo": null,
                    "create_time": null,
                    "update_time": null,
                    "delete_time": 0,
                    "is_change": 0,
                    "dongjie": 0
                } */],
                yewuFinished: false,
                yewuLoading: false,
                yewuQuery: {
                    page: 0,
                    total: 0,
                    list_rows: 100,
                },

            }
        },
        mounted() {
            
            this.onLoadMenDian();
            this.onLoadYeWu();
           
        },
        methods: {
            async dongjieClick(type, id) {
                ///api/home/user/DongJie

                let res = await fly.post("/api/home/user/DongJie", {
                    id, type, token: this.$store.state.options.user.token
                });
              
                if (res.code == 200) {
                   
                    this.$message.success("成功")
                    if (this.activeName == "2") {//暂存点
                        this.yewuList.filter(value => value.id == id)[0].dongjie = type
                    } else {
                        this.menDianList.filter(value => value.id == id)[0].dongjie = type
                    }
                } else {
                    this.$message.error(res.msg)
                }

            },
            shenghe(b,a){
               this.sz=b
              
                this.uid = a;
               this.showAdd = true;
              
              

            },
            async shenhe(){
                console.log(this.sz)
                
                  let res = await fly.post("/api/home/user/confirm", {
                     uid:this.uid,
                     status:this.sz,
                     token: this.$store.state.options.user.token
                });
                this.zhuangtai="通过"
                  this.isow=true
                
                
                if (res.code == 200) {
                   
                    this.$message.success("成功")
                   
                  
                
                } else {
                    
                }

            },
            eventUpdateRequestLimit(limit) {
              

                if (this.activeName == "1") {
                    this.menQuery.list_rows = limit;

                } else {
                }
            },

            async onLoadMenDian() {
               var relf = this;
                let params = this.menQuery;
                params.token = this.$store.state.options.user.token;
                params.status = 5;
                let res = await fly.post("/api/home/user/getListOfMenDian", params);
                
                   let arr = res.data;
                   console.log(arr)
                 if(res.code==200){
                       for(var i=0;i<arr.length;i++){
                        if(arr[i].status==2){
                        
                        relf.zhuangtai="通过"
                        relf.isow=true
                    }else if(arr[i].status==1){
                            relf.zhuangtai="待审核";
                            relf.isow=false;
                    }else if(arr[i].status==0){
                             relf.zhuangtai="驳回";
                               relf.isow=false
                    }

                   }
                 }else{
                     this.menFinished = true
                 }
                   this.menDianList=arr
                // if (res.code == 200) {
                //     console.log(res.data[0].status)
                 
                  
                //     if(res.data[0].status==2){
                        
                //         relf.zhuangtai="通过"
                //     }else if(res.data[0].status==1){
                //             relf.zhuangtai="待审核"
                //     }else if(res.data[0].status==0){
                //              relf.zhuangtai="驳回"
                //     }
                //     this.menDianList = (res.data)
                    
                    
                    
                //      console.log(this.menDianList)
                //     this.menQuery.page++;
                //     if (this.menQuery.list_rows > res.data.length) {
                //         this.menFinished = true
                //     }
                // } else {
                //     this.menFinished = true
                // }
                this.menLoading = false;
            },
            async onLoadYeWu() {
                if (this.yewuLoading) {
                    return
                }

                let params = this.yewuQuery;
                params.token = this.$store.state.options.user.token;
                let res = await fly.post("/api/home/user/getListOfZanCunDian", params);
                if (res.code == 200) {
                    this.yewuList = (res.data)
                    this.yewuQuery.page++;
                    if (this.yewuQuery.list_rows > res.data.length) {
                        this.yewuFinished = true
                    }
                } else {
                    this.yewuFinished = true
                }
                this.yewuLoading = false;
            },


        }
    }
</script>

<style lang="scss" scoped>
    .date-c {
        padding: 10px;
        font-size: 14px;
        height: 80px;
        border-bottom: 3px solid #EEEEEE;
        background-color: white;
        display: flex;
        align-items: center;

        .date {
            padding: 8px 20px;
            border: 1px solid #dddfe2;
            width: 200px;
            border-radius: 5px;
            display: inline-block;
            margin-right: 10px;
        }
    }
 

    .searchBtn {
        display: inline-block;
        padding: 5px 15px;
        font-size: 12px;
        text-align: center;
        color: white;
        background-color: #00CC00;
        margin-top: 5px;
        margin-right: 10px;
    }

    .bac-grey {
        background-color: #A3A3A3 !important;
    }

    .title {
        padding: 10px 10px;
        background-color: #EEEEEE;
    }

    .list {
        padding: 10px;
        font-size: 14px;
        border-bottom: 1px solid #EEEEEE;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
   .jinyong{
       cursor: no-drop;
   }

    .page-top {
        width: 100%;
        height: 3rem;
        position: relative;

        .notice {
            position: absolute;
            top: 0rem;
            width: 100%;
            margin: 0rem;
            padding: 0.7rem 1rem;
            display: flex;
            background: rgba(255, 247, 209, 1);
            z-index: 1;
            box-sizing: border-box;

            dt {
                padding-right: 1rem;

                img {
                    width: 1.4rem;
                }
            }

            dd {
                white-space: nowrap;
                flex: 1;
                margin: 0rem;
                padding: 0rem;
                color: #ff9000;
                font-size: 1.3rem;
            }
        }
    }


</style>

